package admin.data;

import system.ConfigSystem;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;

import models.ConfigModel;

public class ConfigData {
	private Objectify ofy;
	
	public ConfigData() {
		try {
			ObjectifyService.register(ConfigModel.class);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		ofy = ObjectifyService.begin();
	}
	
	public ConfigModel getConfig(long id) {
		ConfigModel config = new ConfigModel();
		try {
			config = ofy.get(new Key<ConfigModel>(ConfigModel.class, id));
		} catch (Exception e) {
			config = null;
		}
		return config;
	}
	
	public void insert(ConfigModel config) {
		ConfigSystem.setConfigs(config);
		ofy.put(config);
	}
	
	public void delete(ConfigModel config) {
		ofy.delete(config);
	}
}
